<template>
  <div>
    <el-form ref="myform" label-width="100px" size="mini">
      <el-row :gutter="40">
        <el-col :span="24">
          <el-form-item label="资产明细">
            <el-table
              :loading="false"
              :data="formItem.details"
              border
              class="fixed-table-table"
              size="mini"
              max-height="240px"
            >
              <el-table-column
                label="序号"
                type="index"
                width="50"
                header-align="center"
                align="center"
              />
              <el-table-column v-for="column in insideColumns" :key="column.key" header-align="center" align="center" :label="column.title" :prop="column.key" :sortable="column.sortable">
                <template slot-scope="scope">
                  <column-render :render="column.render" :row="scope.row" :column="column" />
                </template>
              </el-table-column>
              <el-table-column label="残值（元）">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.salvageValue" style="width:100%" size="mini" :min="0" :precision="2" :step="1" :max="1000000000" />
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label="">
            <el-button size="mini" @click="btnCancel">取 消</el-button>
            <el-button type="primary" @click="commit">提 交</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { confirmDetail as detail, confirmCreate as create } from '@neu/dcam-ui/api/baofeiSL'
// import PageableTable from '@neu/biz-core/components/PageableTable'
const formItem = {
  title: '', // 工单标题
  remark: '',
  workOrderNum: '',
  taskId: '',
  disposeDate: null,
  reason: '',
  comprehensive: true,
  details: []
}
export default {
  components: {
    // PageableTable
  },
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 编辑的表单内容
      formItem: {
        ...formItem
      },
      insideColumns: [
        { title: '资产名称', width: 150, key: 'name' },
        { title: '资产编号', width: 150, key: 'code' },
        { title: '资产分类', width: 300, key: 'type',
          render: (h, params) => {
            let txt = params.row.smallTypeName
            if (params.row.middleTypeName) {
              txt = params.row.middleTypeName + ' / ' + txt
            }
            if (params.row.bigTypeName) {
              txt = params.row.bigTypeName + ' / ' + txt
            }
            return h('span', txt)
          }
        },
        { title: '规格型号', key: 'specifications' },
        { title: '序列号', key: 'serialnumber' },
        { title: '金额（元）', width: 120, key: 'money' }
      ]
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
        })
      }
    },
    commit() {
      this.formItem.workOrderNum = this.workOrderNum
      this.formItem.taskId = this.taskId
      create(this.formItem).then(res => {
        if (res.status === 'success') {
          this.$emit('cancelNewOrderForm', 'refresh')
        }
      })
    },
    btnCancel() {
      this.$emit('cancelNewOrderForm', 'refresh')
    }
  }
}
</script>
